package com.settlement.system.service.kafka.producer;

import com.alibaba.fastjson2.JSONObject;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;

/**
 * 推送NC凭证 消息提供者
 *
 * @author hc
 * @since 2022/04/09
 */
@Service
@Slf4j
public class AcsKafkaProducer {

    @Resource
    private KafkaTemplate<String, String> kafkaTemplate;

    /**
     * 发送消息
     * @param topic 主题
     * @param message 消息信息
     */
    public void sendMessage(final String topic, Object message) {
        String data = JSONObject.toJSONString(message);
        log.info(String.format("kafka发送消息 topic:%s, data:%s----开始", topic, data));
        kafkaTemplate.send(topic, data);
        log.info(String.format("kafka发送消息 topic:%s ----发送成功", topic, data));
    }
}
